package com.hc.model.code02.test6;

import com.hc.model.code02.test5.Singleton;

import java.lang.reflect.Constructor;

/**
 * @version v1.0
 * @ClassName: ReflectDestroySingleton
 * @Description: 反射破坏单例模式实现
 * @Author: HC
 */
public class ReflectDestroySingleton {

    public static void main(String[] args) throws Exception {
        reflectDestroy();
    }

    public static void reflectDestroy() throws Exception {
        Class clazz = Singleton.class;
        Constructor c = clazz.getDeclaredConstructor();
        c.setAccessible(true);
        Singleton s1 = (Singleton) c.newInstance();
        Singleton s2 = (Singleton) c.newInstance();
        System.out.println(s1);
        System.out.println(s2);
    }
}
